package br.com.aquinoevasconcelos.servlets.informativo;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.aquinoevasconcelos.fachada.Fachada;
import br.com.aquinoevasconcelos.modelos.Informativo;
import br.com.aquinoevasconcelos.user.UsuarioAdm;

/**
 * Servlet implementation class AtualizarInformativo
 */
@WebServlet("/AtualizarInformativo")
public class AtualizarInformativo extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public AtualizarInformativo() {
		super();
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Fachada fachada = Fachada.getInstancia();
		Informativo info = new Informativo();
		
		
		UsuarioAdm adm = new UsuarioAdm();
		
		HttpSession session = request.getSession();
		adm = (UsuarioAdm) session.getAttribute("sessaoAdministrador");
		
		ArrayList<UsuarioAdm> adms = new ArrayList<UsuarioAdm>();
		adms.add(adm);
		

		String codigo = request.getParameter("id");
		Long id = Long.parseLong(codigo);
		info.setId(id);
		info.setTitulo(request.getParameter("tituloInformativo"));
		info.setDescricao(request.getParameter("descricaoInformativo"));
		info.setUsuarioAdm(adms);

		try {

			fachada.atualizarInformativo(info);
			response.sendRedirect("ListaInformativo?msg=sucesso");

		} catch (Exception e) {

			response.sendRedirect("pagina_erro/erro.jsp");
		}
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

	}

}
